package com.ushio.gougouwangguo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ushio.gougouwangguo.entity.mysql.ActionConfigMaterials;
import com.ushio.gougouwangguo.entity.qo.ActionConfigMaterialsUpDateQo;
import com.ushio.gougouwangguo.entity.vo.ActionConfigMaterialsVo;
import com.ushio.gougouwangguo.mapper.ActionConfigMaterialsMapper;
import com.ushio.gougouwangguo.service.IActionConfigMaterialsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张文凯
 * @since 2025-09-22
 */
@Service
public class ActionConfigMaterialsServiceImpl extends ServiceImpl<ActionConfigMaterialsMapper, ActionConfigMaterials> implements IActionConfigMaterialsService {

    @Autowired
    ActionConfigMaterialsMapper actionConfigMaterialsMapper;

    @Override
    public List<ActionConfigMaterialsVo> getActionConfigMaterials(Integer actionConfigId) {


        List<ActionConfigMaterialsVo> actionConfigMaterials = actionConfigMaterialsMapper.getActionConfigMaterials(actionConfigId);

        return actionConfigMaterials;
    }

    @Override
    public void updateActionConfigMaterials(ActionConfigMaterialsUpDateQo actionConfigMaterialsUpDateQo) {

        ActionConfigMaterials actionConfigMaterials = ActionConfigMaterials.builder().build();

        BeanUtils.copyProperties(actionConfigMaterialsUpDateQo,actionConfigMaterials);

        if (actionConfigMaterials.getActionConfigMaterialsId()!=null){
            actionConfigMaterialsMapper.updateById(actionConfigMaterials);
        }else{
            actionConfigMaterialsMapper.insert(actionConfigMaterials);
        }


    }

    @Override
    public void deleteActionConfigMaterials(ActionConfigMaterialsUpDateQo actionConfigMaterialsUpDateQo) {

        ActionConfigMaterials actionConfigMaterials = ActionConfigMaterials.builder().actionConfigMaterialsId(actionConfigMaterialsUpDateQo.getActionConfigMaterialsId()).remove(true).build();

        actionConfigMaterialsMapper.updateById(actionConfigMaterials);
    }
}
